import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dbpms.config.SpringConfig;
import com.dbpms.mapper.StudentManageMapper;
import com.dbpms.pojo.*;
import com.dbpms.service.IStudentManageService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import javax.annotation.Resource;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = SpringConfig.class)
public class studentTest {
    @Autowired
    private IStudentManageService service;

    /**
     * 删除学生信息√
     */
    @Test
    public void testDelete(){
        int pd = service.deleteStudentInfo(30,4,null);
        System.out.println(" pd : "+pd);
    }


    /**
     * 修改学生信息√
     */
    @Test
    public void testUpdate(){

        StudentInfo info = new StudentInfo();
        info.setStudentId(30);
        info.setStudentNumber("1");
        info.setStudentName("2");
        info.setStudentGender(1);
        info.setStudentAge(12);
        info.setStudentTime("2020-10-11");
        info.setStudentFamilial("hanzu");
        info.setStudentIdCard("12125125");
        info.setStudentCollegeId(2);
        info.setStudentClassId(2);
        info.setStudentChamberId(3);
        info.setStudentSpecialityId(7);

        String pd = service.updateStudentInfo(info,4);
        System.out.println(" pd : "+pd);
    }
    /**
     * 添加学生信息√
     */
    @Test
    public void testAdd(){

        StudentInfo info = new StudentInfo();
        info.setStudentNumber("52135");
        info.setStudentName("2");
        info.setStudentGender(1);
        info.setStudentAge(12);
        info.setStudentTime("2020-10-11");
        info.setStudentFamilial("hanzu");
        info.setStudentIdCard("12125125");
        info.setStudentCollegeId(2);
        info.setStudentClassId(2);
        info.setStudentChamberId(3);
        info.setStudentSpecialityId(7);

        String pd = service.addStudentInfo(info);
        System.out.println(" pd : "+pd);
    }

    /**
     * 获取全部学生信息 - 使用page分页实现多表联查
     */
    @Resource
    private StudentManageMapper mapper;
    @Test
    public void testSelect(){

        // 分页
        Page<StudentInfo> p = service.page(Page.of(3,5));
        QueryWrapper<StudentInfo> wrapper = new QueryWrapper<StudentInfo>()
                .eq("1",1);
        List<StudentInfo> infos = mapper.queryStdInfo_Page(p,wrapper);
        // 总条数
        System.out.println("total = "+p.getTotal());
        // 总页数
        System.out.println("pages = "+p.getPages());
        infos.forEach(System.out::println);
    }
    /**
     * 根据学号获取单个学生信息
     */
    @Test
    public void testOneSelect(){

        QueryWrapper<StudentInfo> wrapper = new QueryWrapper<StudentInfo>()
                .eq("student_number",5325236);
        List<StudentInfo> infos = mapper.queryStdInfo_Page(null,wrapper);

        infos.forEach(System.out::println);
    }
    /**
     * 获取全部学院信息
     */
    @Test
    public void testSelectCollage(){

        List<CollegeInfo> infos = service.queryCollegeInfo();

        System.out.println(infos);
    }
    /**
     * 根据学院获取所属专业
     */
    @Test
    public void testSelectByCollageSpe(){

        List<SpecialityInfo> infos = service.querySpecialityInfo(1);

        System.out.println(infos);
    }
    /**
     * 根据专业获取所属班级
     */
    @Test
    public void testSelectBySpeClass(){

        List<ClassInfo> infos = service.queryClassInfo(2);

        System.out.println(infos);
    }
}
